//
//  HMWelCome.swift
//  TJHWeiBo
//
//  Created by tianjunhui on 16/8/12.
//  Copyright © 2016年 itcast.cn. All rights reserved.
//

import UIKit

class HMWelCome: UIViewController {

  
    
    override func viewDidAppear(animated: Bool) {
        super.viewDidAppear(animated)
        // 更改头像的顶部约束
        self.txImageView.snp_updateConstraints { (make) -> Void in
            make.top.equalTo(self.view).offset(100)
        }
        
        // 设置动画
        /*
         - 动画时间
         - 延迟时间
         - 阻尼系数 (阻尼系数 0-1  越小 弹性效果越大)
         - 起始速度
         - options
         */
        UIView.animateWithDuration(2, delay: 1, usingSpringWithDamping: 0.7, initialSpringVelocity: 0, options: [], animations: { () -> Void in
            //强制刷新UI(如果你使用的是约束 就需要这么干)
            self.view.layoutIfNeeded()
        }) { (_) -> Void in
            UIView.animateWithDuration(0.25, animations: { () -> Void in
                self.WELabel.alpha = 1
                }, completion: { (_) -> Void in
                    // 发送通知告知appdelegate 切换根控制器
                    NSNotificationCenter.defaultCenter().postNotificationName(WBSWITCHROOTVCNOTIFICATION, object: nil)
            })
        }
        

  
    }
    
    override func viewDidLoad() {
        super.viewDidLoad()
        
        setUpUI()
    }
    
    //设置视图
    private func setUpUI(){
        
        //添加控件
        view.addSubview(bgImageView)
        view.addSubview(txImageView)
        view.addSubview(WELabel)
        //添加约束
        bgImageView.snp_makeConstraints { (make) in
            make.edges.equalTo(view).offset(UIEdgeInsetsZero)
            
        txImageView.snp_makeConstraints(closure: { (make) in
            make.size.equalTo(CGSize(width: 90, height: 90))
            make.centerX.equalTo(view)
            make.top.equalTo(view).offset(400)
        })
        WELabel.snp_makeConstraints(closure: { (make) in
            make.centerX.equalTo(view)
            make.top.equalTo(txImageView.snp_bottom).offset(20)
        })
        }
        
    }
    
    //懒加载背景图片
    private lazy var bgImageView: UIImageView = UIImageView(imageName: "ad_background")
    //加载头像
    private lazy var txImageView: UIImageView = {
        
        let img = UIImageView(imageName: "avatar_default_big")
        img.hm_setImageWithString(HMUserAccountViewModel.sharedTools.userAccount?.avatar_large, placeholderImgName: "avatar_default_big")
        img.layer.cornerRadius = 45
//        img.layer.masksToBounds = true
        return img
    
    }()
    //设置文字
    private lazy var WELabel: UILabel = {
        let lab = UILabel()
        lab.font = UIFont.systemFontOfSize(18)
        lab.text = "欢迎回来"
        lab.textColor = AppThemeColor
        lab.textAlignment = .Center
        lab.alpha = 0
        return lab
   
    }()
    
    
}
